package com.zhuss.core.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zhuss.bean.bo.core.user.CreateUserBo;
import com.zhuss.bean.bo.core.user.DeleteUserBo;
import com.zhuss.bean.bo.core.user.ResetPwdBo;
import com.zhuss.bean.bo.core.user.StartUserBo;
import com.zhuss.bean.bo.core.user.StopUserBo;
import com.zhuss.bean.bo.core.user.UpdateUserBo;
import com.zhuss.bean.bo.core.user.UserRoleBindBo;
import com.zhuss.common.OperateService;
import com.zhuss.common.Processor;
import com.zhuss.exception.OceanException;

/**
 * 用户操作service（基本操作）
 * @author zhushanshuo
 * @Date 2019-12-13 15:59
 *
 */
@Component("userOperateService")
public class UserOperateService implements OperateService<Void, Object> {
	
	@Autowired
	@Qualifier("userCreate")
	private Processor<Object, CreateUserBo> userCreate;
	
	@Autowired
	@Qualifier("userUpdate")
	private Processor<Object, UpdateUserBo> userUpdate;
	
	
	@Autowired
	@Qualifier("userDelete")
	private Processor<Object, DeleteUserBo> userDelete;
	
	
	@Autowired
	@Qualifier("userStart")
	private Processor<Object, StartUserBo> userStart;
	
	@Autowired
	@Qualifier("userStop")
	private Processor<Object, StopUserBo> userStop;
	
	@Autowired
	@Qualifier("userRoleBind")
	private Processor<Object, UserRoleBindBo> userRoleBind;
	
	
	@Autowired
	@Qualifier("pwdReset")
	private Processor<Object, ResetPwdBo> pwdReset;
	
	/**
	 * 创建
	 */
	@Override
    @Transactional(rollbackFor = Exception.class)
	public Void create(Object param) throws OceanException {
		
		CreateUserBo bo = (CreateUserBo) param;
		
		userCreate.process(bo);
		
		return null;
	}
    
	/**
	 * 修改
	 */
	@Override
    @Transactional(rollbackFor = Exception.class)
    public Void update(Object param) throws OceanException {
    	
		UpdateUserBo bo = (UpdateUserBo) param;
		
		userUpdate.process(bo);
		
    	return null;
    }
	
	/**
	 * 删除
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public Void delete(Object param) throws OceanException {
		
		DeleteUserBo bo = (DeleteUserBo) param;
		
		userDelete.process(bo);
		
		return null;
	}
	
	
	/**
	 * 启用
	 */
	@Transactional(rollbackFor = Exception.class)
	protected Void start(Object param) throws OceanException {
		
		StartUserBo bo = (StartUserBo) param;
		
		userStart.process(bo);
		
		return null;
	}
	
	/**
	 * 停用
	 */
	@Transactional(rollbackFor = Exception.class)
	protected Void stop(Object param) throws OceanException {
		
		StopUserBo bo = (StopUserBo) param;
		
		userStop.process(bo);
		
		return null;
	}
	
	
	/**
	 * 给用户绑定角色
	 */
	@Transactional(rollbackFor = Exception.class)
	public Void userRoleBind(Object param) throws OceanException {
		
		UserRoleBindBo bo = (UserRoleBindBo) param;
		
		userRoleBind.process(bo);
		
		return null;
	}
	
	
	/**
	 * 重置密码
	 */
	@Transactional(rollbackFor = Exception.class)
	protected Void resetPwd(Object param) throws OceanException {
		
		ResetPwdBo bo = (ResetPwdBo) param;
		
		pwdReset.process(bo);
		
		return null;
	}
	
}

